/**
 * Copyright 2006 Brad Reynolds
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.leeloo.databinding.internal.ui;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.leeloo.databinding.ui.event.FireBindingEventEvent;
import org.leeloo.databinding.ui.event.ResumeEvent;
import org.leeloo.databinding.ui.test.support.PluginTestCase;

public class EventViewerBuilderTest extends PluginTestCase {
	private Shell shell;
	
	protected void tearDown() throws Exception {
		if (shell != null && !shell.isDisposed()) {
			shell.dispose();
		}
		
		super.tearDown();
	}
	
	public void testBuildViewer() throws Exception {
		shell = new Shell();
		
		EventViewerBuilder builder = new EventViewerBuilder();
		builder.setParent(shell);
		
		TableViewer viewer = builder.build();
		Table table = viewer.getTable();
		assertNotNull(viewer);
		assertEquals(2, table.getColumnCount());
		assertNotNull(viewer.getContentProvider());
		assertNotNull(viewer.getLabelProvider());
	}
        
    /**
     * Asserts that for debugger events a background color is returned.
     * 
     * @throws Exception
     */
    public void testLabelProviderImage() throws Exception {
       shell = new Shell();
       
       EventViewerBuilder builder = new EventViewerBuilder();
       builder.setParent(shell);
       
       TableViewer viewer = builder.build();
       
       ITableLabelProvider provider = (ITableLabelProvider) viewer.getLabelProvider();
       
       assertNotNull(provider.getColumnImage(new ResumeEvent(), 0));
       assertNull(provider.getColumnImage(new ResumeEvent(), 1));
       assertNull(provider.getColumnImage(new FireBindingEventEvent(), 0));
    }
}
